<script>
/**
 * 分类编辑
 * @Author Mumu xinglinhe@qq.com
 * @Date 2022/09/13
 */
import ImgUp from '@/components/fileupImgBase'
export default{
	components:{
		ImgUp,
	},
	props:{

	},
	data(){
		return {
			visible:false,
			data:{},
			loading:false,
			
			fileupthumb:{
				file:{},
				filelist:[],
			},
		}
	},
	created(){},
	mounted(){},
	methods:{
		send(){
			this.$refs.forms.validate().then(async ()=>{
				console.log('验证通过');
				this.loading=true;
				let rs
				if(this.param?.id){
					rs = await this.muajax.classEdit_data({
						...this.data,
					});
				}else{
					rs = await this.muajax.classAdd_data({
						...this.data,
					});
				}
				this.loading=false;
				if(rs.status==200){
					this.$message.success(rs.msg);
					this.visible=false;
					this.$emit('saved')
				}
			}).catch(err=>{
				console.log(err);
				// this.$errorFocus(err);
			})
		},
		async datainit(){
			this.data=this.param
			if(this.param.cover_img){
				this.fileupthumb.filelist.push({
						uid: '-1',
						name: '封面',
						status: 'done',
						url:this.param.cover_img,
				})
			}
			// let rs = await this.muajax.fodGet({ id : this.param.id});
			// if(rs.status==200){
			// 	this.data=rs.data;
			// 	this.$emit('saved')
			// }
		},//初始化本页数据
		show(show,param){
			this.visible=show;
			if(show){
				this.data={sort:10,};
				this.param=param;
				this.fileupthumb.filelist=[];
				if(!!this.param?.id)
					this.datainit();
			}
		},
		setthumb(path){
			console.log(path)
			this.data.cover=path;
			// this.fileupthumb.filelist=[{
			// 							uid: '-1',
			// 							name: '视频封面',
			// 							status: 'done',
			// 							url:path,
			// 					}]
		},//视频上传自动更新封面

	},
	computed:{},
	watch:{},
	filters:{},
}
</script>
<template>
	<a-modal
		v-model:visible="visible"
		width="500px"
		title="分类编辑"
		:maskClosable="false"
		@ok="send"
		cancelText="取消"
		okText="提交"
		:confirmLoading="loading"
	>
		<a-form
		ref="forms"
		:model="data"
		>
			<div class="upbox">
				<a-form-item
					label="封面"
					:labelCol="{span: 4}"
					name="cover_img"
					:rules="[{required:true,message:'请上传图片',trigger: 'blur'}]"
				>
					<ImgUp
						accept="image/png, image/jpeg"
						:fileup="fileupthumb"
						:api="muajax.api.uploadFile"
						@done="head=>data.cover_img=head"
						@del="data.cover_img=''"
					/>
				</a-form-item>
			</div>
			<a-form-item
				label="分类名称"
				:labelCol="{span: 4}"
				name="name"
				:rules="[{required:true,message:'请输入分类名称'}]"
			>
				<a-input
					placeholder="请输入"
					v-model:value="data.name"
				/>
			</a-form-item>
			<a-form-item
				label="排序"
				:labelCol="{span: 4}"
				name="sort"
				:rules="[{required:true,type:'number',message:'请输入排序'}]"
			>
				<a-input-number
					:defaultValue="10"
					placeholder="请输入"
					v-model:value="data.sort"
					:min="0"
					:max="9999"
				/>
			</a-form-item>
		</a-form>
	</a-modal>
</template>
<style lang="less" scoped>

</style>